home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / raytrace / pov / bin / xtras / frame.h < prev    next >
C/C++ Source or Header  |  1994-09-11  |  30KB  |  1,199 lines

  1. /****************************************************************************
  2. *
  3. *  ATTENTION!!!
  4. *
  5. *  THIS FILE HAS BEEN MODIFIED!!! IT IS NOT PART OF THE OFFICAL
  6. *  POV-RAY 2.2 DISTRIBUTION!!!
  7. *
  8. *  THIS FILE IS PART OF "FASTER THAN POV-RAY" (VERSION 2.2),
  9. *  A SPED-UP VERSION OF POV-RAY 2.2. USE AT YOUR OWN RISK!!!!!!
  10. *
  11. *  New files: addon0.c, addon1.c, addon2.c, addon3.c, addon.h
  12. *
  13. *  The additional modules were written by Dieter Bayer.
  14. *
  15. *  Send comments, suggestions, bugs, ideas ... to:
  16. *
  17. *  e-mail: dieter@cip.e-technik.uni-erlangen.de
  18. *  CIS: 100255.3074
  19. *
  20. *  All changed/added lines are enclosed in #ifdef DB_CODE ... #endif
  21. *
  22. *  The vista projection was taken from:
  23. *
  24. *    A. Hashimoto, T. Akimoto, K. Mase, and Y. Suenaga, 
  25. *    "Vista Ray-Tracing: High Speed Ray Tracing Using Perspective
  26. *    Projection Image", New Advances in Computer Graphics, Proceedings
  27. *    of CG International '89, R. A. Earnshaw, B. Wyvill (Eds.), 
  28. *    Springer, ..., pp. 549-560
  29. *
  30. *  The idea for the light buffer was taken from:
  31. *
  32. *    E. Haines and D. Greenberg, "The Light Buffer: A Shadow-Testing 
  33. *    Accelerator", IEEE CG&A, Vol. 6, No. 9, Sept. 1986, pp. 6-16
  34. *
  35. *****************************************************************************/
  36.  
  37. /****************************************************************************
  38. *                   frame.h
  39. *
  40. *  This header file is included by all C modules in POV-Ray. It defines all
  41. *  globally-accessible types and constants.
  42. *
  43. *  from Persistence of Vision Raytracer
  44. *  Copyright 1993 Persistence of Vision Team
  45. *---------------------------------------------------------------------------
  46. *  NOTICE: This source code file is provided so that users may experiment
  47. *  with enhancements to POV-Ray and to port the software to platforms other 
  48. *  than those supported by the POV-Ray Team.  There are strict rules under
  49. *  which you are permitted to use this file.  The rules are in the file
  50. *  named POVLEGAL.DOC which should be distributed with this file. If 
  51. *  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  52. *  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  53. *  Forum.  The latest version of POV-Ray may be found there as well.
  54. *
  55. * This program is based on the popular DKB raytracer version 2.12.
  56. * DKBTrace was originally written by David K. Buck.
  57. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  58. *
  59. *****************************************************************************/
  60.  
  61. /* Generic header for all modules */
  62.  
  63. #include <math.h>
  64. #include <stdio.h>
  65. #include <string.h>
  66. #include <limits.h>
  67. #include "config.h"
  68.  
  69. /* use the modified/added code of the FTPOV-Ray distribution. DB */
  70.  
  71. #define DB_CODE
  72.  
  73.  
  74. /* These are used by POVRAY.C and the machine specific modules */
  75.  
  76. #define POV_RAY_VERSION "2.2"
  77.  
  78. /* This message is for the personal distribution release. */
  79.  
  80. #ifdef DB_CODE
  81.   #define DISTRIBUTION_MESSAGE_1 "FASTER THAN POV-Ray (Ver 2.2) (sped-up and unoffical) by:"
  82.   #define DISTRIBUTION_MESSAGE_2 "Dieter Bayer (e-mail: dieter@cip.e-technik.uni-erlangen.de)"
  83. #else
  84.   #define DISTRIBUTION_MESSAGE_1 "This is an unofficial version compiled by:"
  85.   #define DISTRIBUTION_MESSAGE_2 "FILL IN NAME HERE........................."
  86. #endif
  87. #define DISTRIBUTION_MESSAGE_3 "The POV-Ray Team is not responsible for supporting this version."
  88.  
  89. #ifndef READ_ENV_VAR_BEFORE 
  90. #define READ_ENV_VAR_BEFORE 
  91. #endif
  92. #ifndef READ_ENV_VAR_AFTER
  93. #define READ_ENV_VAR_AFTER if ((Option_String_Ptr = getenv("POVRAYOPT")) != NULL) read_options(Option_String_Ptr);   
  94. #endif
  95.  
  96. #ifndef CONFIG_MATH
  97. #define CONFIG_MATH
  98. #endif
  99.  
  100. #ifndef EPSILON
  101. #define EPSILON 1.0e-10
  102. #endif
  103.  
  104. #ifndef FILE_NAME_LENGTH
  105. #define FILE_NAME_LENGTH 150
  106. #endif
  107.  
  108. #ifndef HUGE_VAL
  109. #define HUGE_VAL 1.0e+17
  110. #endif
  111.  
  112. #ifndef BOUND_HUGE
  113. #define BOUND_HUGE 1.0e30
  114. #endif
  115.  
  116. #ifndef DBL_FORMAT_STRING
  117. #define DBL_FORMAT_STRING "%lf"
  118. #endif
  119.  
  120. #ifndef DEFAULT_OUTPUT_FORMAT
  121. #define DEFAULT_OUTPUT_FORMAT    'd'
  122. #endif
  123.  
  124. #ifndef RED_RAW_FILE_EXTENSION
  125. #define RED_RAW_FILE_EXTENSION ".red"
  126. #endif
  127.  
  128. #ifndef GREEN_RAW_FILE_EXTENSION
  129. #define GREEN_RAW_FILE_EXTENSION ".grn"
  130. #endif
  131.  
  132. #ifndef BLUE_RAW_FILE_EXTENSION
  133. #define BLUE_RAW_FILE_EXTENSION ".blu"
  134. #endif
  135.  
  136. #ifndef FILENAME_SEPARATOR
  137. #define FILENAME_SEPARATOR "/"
  138. #endif
  139.  
  140. /* 0==yes 1==no 2==opt */
  141. #ifndef CASE_SENSITIVE_DEFAULT
  142. #define CASE_SENSITIVE_DEFAULT 0
  143. #endif
  144.  
  145. #ifndef READ_FILE_STRING
  146. #define READ_FILE_STRING "rb"
  147. #endif
  148.  
  149. #ifndef WRITE_FILE_STRING
  150. #define WRITE_FILE_STRING "wb"
  151. #endif
  152.  
  153. #ifndef APPEND_FILE_STRING
  154. #define APPEND_FILE_STRING "ab"
  155. #endif
  156.  
  157. #ifndef NORMAL
  158. #define NORMAL '0'
  159. #endif
  160.  
  161. #ifndef GREY
  162. #define GREY   'G'
  163. #endif
  164.  
  165. #ifndef START_TIME
  166. #define START_TIME time(&tstart);     
  167. #endif
  168.  
  169. #ifndef STOP_TIME
  170. #define STOP_TIME  time(&tstop);
  171. #endif
  172.  
  173. #ifndef TIME_ELAPSED
  174. #define TIME_ELAPSED difftime (tstop, tstart);
  175. #endif
  176.  
  177. #ifndef STARTUP_POVRAY
  178. #define STARTUP_POVRAY
  179. #endif
  180.  
  181. #ifndef PRINT_OTHER_CREDITS
  182. #define PRINT_OTHER_CREDITS
  183. #endif
  184.  
  185. #ifndef TEST_ABORT
  186. #define TEST_ABORT
  187. #endif
  188.  
  189. #ifndef FINISH_POVRAY
  190. #define FINISH_POVRAY
  191. #endif
  192.  
  193. #ifndef COOPERATE
  194. #define COOPERATE 
  195. #endif
  196.  
  197. #ifndef DBL
  198. #define DBL double
  199. #endif
  200.  
  201. #ifndef ACOS
  202. #define ACOS acos
  203. #endif
  204.  
  205. #ifndef SQRT
  206. #define SQRT sqrt
  207. #endif
  208.  
  209. #ifndef POW
  210. #define POW pow
  211. #endif
  212.  
  213. #ifndef COS
  214. #define COS cos
  215. #endif
  216.  
  217. #ifndef SIN
  218. #define SIN sin
  219. #endif
  220.  
  221. #ifndef labs
  222. #define labs(x) (long) ((x<0)?-x:x)
  223. #endif
  224.  
  225. #ifndef max
  226. #define max(x,y) ((x<y)?y:x)
  227. #endif
  228.  
  229. #ifndef STRLN
  230. #define STRLN(x) x
  231. #endif
  232.  
  233. #ifndef PARAMS
  234. #define PARAMS(x) x
  235. #endif
  236.  
  237. #ifndef ANSIFUNC
  238. #define ANSIFUNC 1
  239. #endif
  240.  
  241. #ifndef M_PI
  242. #define M_PI 3.1415926535897932384626
  243. #endif
  244.  
  245. #ifndef TRUE
  246. #define TRUE 1
  247. #define FALSE 0
  248. #endif
  249.  
  250. #ifndef IFF_SWITCH_CAST
  251. #define IFF_SWITCH_CAST (int)
  252. #endif
  253.  
  254. #ifndef PRINT_CREDITS
  255. #define PRINT_CREDITS print_credits();
  256. #endif
  257.  
  258. #ifndef PRINT_STATS
  259. #define PRINT_STATS print_stats();
  260. #endif
  261.  
  262. #ifndef MAX_CONSTANTS
  263. #define MAX_CONSTANTS 1000
  264. #endif
  265.  
  266. #ifndef WAIT_FOR_KEYPRESS
  267. #define WAIT_FOR_KEYPRESS
  268. #endif
  269.  
  270. #ifndef CDECL
  271. #define CDECL
  272. #endif
  273.  
  274. #ifndef MAX_BUFSIZE
  275. #define MAX_BUFSIZE INT_MAX
  276. #endif
  277.  
  278. /* If compiler version is undefined, then make it 'u' for unknown */
  279. #ifndef COMPILER_VER
  280. #define COMPILER_VER ".u"
  281. #endif
  282.  
  283. #ifndef QSORT_FUNCT_RET
  284. #define QSORT_FUNCT_RET int CDECL
  285. #endif
  286.  
  287. #ifndef QSORT_FUNCT_PARAM
  288. #define QSORT_FUNCT_PARAM void *
  289. #endif
  290.  
  291. #ifndef MAIN_RETURN_TYPE
  292. #define MAIN_RETURN_TYPE void
  293. #endif
  294.  
  295. #ifndef MAIN_RETURN_STATEMENT
  296. #define MAIN_RETURN_STATEMENT
  297. #endif
  298.  
  299. /* These values determine the minumum and maximum distances
  300.    that qualify as ray-object intersections */
  301. #define Small_Tolerance 0.001
  302. #define Max_Distance 1.0e7
  303.  
  304. #ifdef DB_CODE
  305.  
  306. /* define structures needed for vista/light tree */
  307.  
  308. typedef struct Project_Struct PROJECT;
  309.  
  310. typedef struct Project_Tree_Node_Struct PROJECT_TREE_NODE;
  311. typedef struct Project_Tree_Leaf_Struct PROJECT_TREE_LEAF;
  312.  
  313. struct Project_Struct
  314. {
  315.   int x1, y1, x2, y2;
  316. };
  317.  
  318. #endif
  319.  
  320.  
  321. typedef struct istk_entry INTERSECTION;
  322. typedef struct Vector_Struct VECTOR;
  323. typedef DBL MATRIX [4][4];
  324. typedef struct Bounding_Box_Struct BBOX;
  325. typedef struct Colour_Struct COLOUR;
  326. typedef struct Colour_Map_Entry COLOUR_MAP_ENTRY;
  327. typedef struct Colour_Map_Struct COLOUR_MAP;
  328. typedef struct Transform_Struct TRANSFORM;
  329. typedef struct Image_Struct IMAGE;
  330. typedef struct Texture_Struct TEXTURE;
  331. typedef struct Material_Texture_Struct MATERIAL;
  332. typedef struct Tiles_Texture_Struct TILES;
  333. typedef struct Pattern_Struct TPATTERN;
  334. typedef struct Pigment_Struct PIGMENT;
  335. typedef struct Tnormal_Struct TNORMAL;
  336. typedef struct Finish_Struct FINISH;
  337. typedef struct Method_Struct METHODS;
  338. typedef struct Camera_Struct CAMERA;
  339. typedef struct Object_Struct OBJECT;
  340. typedef struct Composite_Struct COMPOSITE;
  341. typedef struct Sphere_Struct SPHERE;
  342. typedef struct Quadric_Struct QUADRIC;
  343. typedef struct Poly_Struct POLY;
  344. typedef struct Disc_Struct DISC;
  345. typedef struct Cone_Struct CYLINDER;
  346. typedef struct Cone_Struct CONE;
  347. typedef struct Light_Source_Struct LIGHT_SOURCE;
  348. typedef struct Bicubic_Patch_Struct BICUBIC_PATCH;
  349. typedef struct Triangle_Struct TRIANGLE;
  350. typedef struct Smooth_Triangle_Struct SMOOTH_TRIANGLE;
  351. typedef struct Plane_Struct PLANE;
  352. typedef struct CSG_Struct CSG;
  353. typedef struct Box_Struct BOX;
  354. typedef struct Blob_Struct BLOB;
  355. typedef struct Ray_Struct RAY;
  356. typedef struct Frame_Struct FRAME;
  357. typedef struct istack_struct ISTACK;
  358. typedef int TOKEN;
  359. typedef int CONSTANT;
  360. typedef struct Chunk_Header_Struct CHUNK_HEADER;
  361. typedef struct Data_File_Struct DATA_FILE;
  362. typedef struct complex_block complex;
  363. typedef struct Height_Field_Struct HEIGHT_FIELD;
  364. typedef short WORD;
  365.  
  366. struct Vector_Struct
  367.   {
  368.    DBL x, y, z;
  369.   };
  370. #define Destroy_Vector(x) if ((x)!=NULL) free(x)
  371. #define Destroy_Float(x) if ((x)!=NULL) free(x)
  372.  
  373. struct Colour_Struct
  374.   {
  375.    DBL Red, Green, Blue, Filter;
  376.   };
  377.  
  378. #define Make_Colour(c,r,g,b) {(c)->Red=(r);(c)->Green=(g);(c)->Blue=(b);(c)->Filter=0.0;}
  379. #define Make_ColourA(c,r,g,b,a) {(c)->Red=(r);(c)->Green=(g);(c)->Blue=(b);(c)->Filter=(a);}
  380. #define Make_Vector(v,a,b,c) { (v)->x=(a);(v)->y=(b);(v)->z=(c); }
  381. #define Destroy_Colour(x) if ((x)!=NULL) free(x)
  382. #define MAX_COLOUR_MAP_ENTRIES 40
  383.  
  384. struct Colour_Map_Entry
  385.   {
  386.    DBL value;
  387.    COLOUR Colour;
  388.   };
  389.  
  390. struct Colour_Map_Struct
  391.   {
  392.    int Number_Of_Entries, Transparency_Flag, Users;
  393.    COLOUR_MAP_ENTRY *Colour_Map_Entries;
  394.   };
  395.  
  396. struct Transform_Struct
  397.   {
  398.    MATRIX matrix;
  399.    MATRIX inverse;
  400.   };
  401.  
  402. #define Destroy_Transform(x) if ((x)!=NULL) free(x)
  403.  
  404. /* Types for reading IFF files. */
  405. typedef struct {unsigned short Red, Green, Blue, Filter;} IMAGE_COLOUR;
  406.  
  407. struct Image_Line
  408.   {
  409.    unsigned char *red, *green, *blue;
  410.   };
  411.  
  412. typedef struct Image_Line IMAGE_LINE;
  413.  
  414. /* Legal image attributes */
  415. #define GIF_FILE   1
  416. #define POT_FILE   2
  417. #define DUMP_FILE  4
  418. #define IFF_FILE   8
  419. #define TGA_FILE  16
  420. #define GRAD_FILE 32
  421.  
  422. #define IMAGE_FILE    GIF_FILE+DUMP_FILE+IFF_FILE+GRAD_FILE+TGA_FILE
  423. #define NORMAL_FILE   GIF_FILE+DUMP_FILE+IFF_FILE+GRAD_FILE+TGA_FILE
  424. #define MATERIAL_FILE GIF_FILE+DUMP_FILE+IFF_FILE+GRAD_FILE+TGA_FILE
  425. #define HF_FILE       GIF_FILE+POT_FILE+TGA_FILE
  426.  
  427. struct Image_Struct
  428.   {
  429.    int Map_Type;
  430.    int File_Type;
  431.    int Interpolation_Type;
  432.    short Once_Flag;
  433.    short Use_Colour_Flag;
  434.    VECTOR Gradient;
  435.    DBL width, height;
  436.    int iwidth, iheight;
  437.    short Colour_Map_Size;
  438.    IMAGE_COLOUR *Colour_Map;
  439.    union 
  440.     {
  441.      IMAGE_LINE *rgb_lines;
  442.      unsigned char **map_lines;
  443.     } data;  
  444.   };
  445.  
  446. /* Texture types */
  447. #define PNF_TEXTURE     0
  448. #define TILE_TEXTURE    1
  449. #define MAT_TEXTURE     2
  450.  
  451. /* Image/Bump Map projection types */
  452. #define PLANAR_MAP      0
  453. #define SPHERICAL_MAP   1
  454. #define CYLINDRICAL_MAP 2
  455. #define PARABOLIC_MAP   3
  456. #define HYPERBOLIC_MAP  4
  457. #define TORUS_MAP       5
  458. #define PIRIFORM_MAP    6
  459. #define OLD_MAP         7
  460.  
  461. /* Bit map interpolation types */
  462. #define NO_INTERPOLATION 0
  463. #define NEAREST_NEIGHBOR 1
  464. #define BILINEAR         2
  465. #define CUBIC_SPLINE     3
  466. #define NORMALIZED_DIST  4
  467.  
  468. /* Coloration pigment list */
  469. #define NO_PIGMENT               0
  470. #define COLOUR_PIGMENT           1
  471. #define BOZO_PIGMENT             2
  472. #define MARBLE_PIGMENT           3
  473. #define WOOD_PIGMENT             4
  474. #define CHECKER_PIGMENT          5
  475. #define SPOTTED_PIGMENT          6
  476. #define AGATE_PIGMENT            7
  477. #define GRANITE_PIGMENT          8
  478. #define GRADIENT_PIGMENT         9
  479. #define IMAGE_MAP_PIGMENT       10
  480. #define PAINTED1_PIGMENT        11
  481. #define PAINTED2_PIGMENT        12
  482. #define PAINTED3_PIGMENT        13
  483. #define ONION_PIGMENT           14
  484. #define LEOPARD_PIGMENT         15
  485. #define BRICK_PIGMENT           16
  486. #define MANDEL_PIGMENT          17
  487. #define HEXAGON_PIGMENT         18
  488. #define RADIAL_PIGMENT          19
  489.  
  490.  
  491. /* Normal perturbation (bumpy) texture list  */
  492. #define NO_NORMAL  0
  493. #define WAVES      1
  494. #define RIPPLES    2
  495. #define WRINKLES   3
  496. #define BUMPS      4
  497. #define DENTS      5
  498. #define BUMPY1     6
  499. #define BUMPY2     7
  500. #define BUMPY3     8
  501. #define BUMP_MAP   9
  502.  
  503. /* Pattern flags */
  504. #define NO_FLAGS      0
  505. #define HAS_FILTER    1
  506. #define FULL_BLOCKING 2
  507. #define HAS_TURB      4
  508. #define POST_DONE     8
  509.  
  510. #define TPATTERN_FIELDS int Type, Octaves, Flags; VECTOR Turbulence;  \
  511.   DBL omega, lambda, Frequency, Phase; IMAGE *Image; TRANSFORM *Trans;
  512.  
  513. #define INIT_TPATTERN_FIELDS(p,t) p->Type=t; p->Octaves=6; p->Image=NULL; \
  514.  p->Frequency=1.0; p->Phase=0.0;\
  515.  p->Trans=NULL; p->Flags=NO_FLAGS; p->omega=0.5;p->lambda=2.0; \
  516.  Make_Vector(&(p->Turbulence),0.0,0.0,0.0);
  517.  
  518. /* This is an abstract structure that is never actually used.
  519.    Pigment and Tnormal are descendents of this primative type */
  520.  
  521. struct Pattern_Struct
  522.   {
  523.    TPATTERN_FIELDS
  524.   };
  525.  
  526. struct Pigment_Struct
  527.   {
  528.    TPATTERN_FIELDS
  529.    COLOUR *Colour1;
  530.    COLOUR Quick_Colour;
  531.    COLOUR_MAP *Colour_Map;
  532.    VECTOR Colour_Gradient;
  533.    DBL Mortar, Agate_Turb_Scale;
  534.    int Iterations; /* mhs 10/92 for fractal textures */
  535.   };
  536.  
  537. struct Tnormal_Struct
  538.   {
  539.    TPATTERN_FIELDS
  540.    DBL Amount;
  541.   };
  542.  
  543. struct Finish_Struct
  544.   {
  545.    DBL Reflection, Ambient, Diffuse, Brilliance, Index_Of_Refraction;
  546.    DBL Refraction, Specular, Roughness, Phong, Phong_Size;
  547.    DBL Crand;
  548.    short Metallic_Flag;
  549.   };
  550.  
  551. #define Destroy_Finish(x) if ((x)!=NULL) free(x)
  552.  
  553. #define TEXTURE_FIELDS unsigned char Type,Flags; TEXTURE *Next_Material; \
  554.  TEXTURE *Next_Layer;
  555. #define TRANS_TEXTURE_FIELDS TEXTURE_FIELDS TRANSFORM *Trans;
  556.  
  557. struct Texture_Struct
  558.   {
  559.    TEXTURE_FIELDS
  560.    PIGMENT *Pigment;
  561.    TNORMAL *Tnormal;
  562.    FINISH *Finish;
  563.   };
  564.  
  565. struct Tiles_Texture_Struct
  566.   {
  567.    TRANS_TEXTURE_FIELDS
  568.    TEXTURE *Tile1;
  569.    TEXTURE *Tile2;
  570.   };
  571.  
  572. struct Material_Texture_Struct
  573.   {
  574.    TRANS_TEXTURE_FIELDS
  575.    TEXTURE *Materials;
  576.    IMAGE *Image;
  577.    int Num_Of_Mats;
  578.   };
  579.  
  580. /* Object types */
  581. #define BASIC_OBJECT            0
  582. #define PATCH_OBJECT            1   /* Has no inside, no inverse */
  583. #define TEXTURED_OBJECT         2   /* Has texture, possibly in children */
  584.  
  585. #define CHILDREN_FLAGS (PATCH_OBJECT+TEXTURED_OBJECT)
  586.                     /* Reverse inherited flags */
  587.  
  588. #define COMPOUND_OBJECT         4   /* Has children field */
  589. #define STURM_OK_OBJECT         8   /* STRUM legal */
  590. #define WATER_LEVEL_OK_OBJECT  16   /* WATER_LEVEL legal */
  591. #define LIGHT_SOURCE_OBJECT    32   /* link me in frame.light_sources */
  592. #define BOUNDING_OBJECT        64   /* This is a holder for bounded object */
  593. #define SMOOTH_OK_OBJECT      128   /* SMOOTH legal */
  594. #define IS_CHILD_OBJECT       256   /* Object is inside a COMPOUND */
  595. #define DOUBLE_ILLUMINATE     512   /* Illuminate both sides of surface to
  596.                        avoid normal purturb bug */
  597.  
  598.  
  599. #define COMPOSITE_OBJECT       (BOUNDING_OBJECT)
  600. #define SPHERE_OBJECT          (BASIC_OBJECT)
  601. #define PLANE_OBJECT           (BASIC_OBJECT)
  602. #define QUADRIC_OBJECT         (BASIC_OBJECT)
  603. #define BOX_OBJECT             (BASIC_OBJECT)
  604. #define CONE_OBJECT            (BASIC_OBJECT)
  605. #define DISC_OBJECT            (BASIC_OBJECT)
  606. #define HEIGHT_FIELD_OBJECT    (BASIC_OBJECT+WATER_LEVEL_OK_OBJECT+SMOOTH_OK_OBJECT)
  607. #define TRIANGLE_OBJECT        (PATCH_OBJECT)
  608. #define SMOOTH_TRIANGLE_OBJECT (PATCH_OBJECT+DOUBLE_ILLUMINATE)
  609. #define BICUBIC_PATCH_OBJECT   (PATCH_OBJECT+DOUBLE_ILLUMINATE)
  610. #define UNION_OBJECT           (COMPOUND_OBJECT)
  611. #define MERGE_OBJECT           (COMPOUND_OBJECT)
  612. #define INTERSECTION_OBJECT    (COMPOUND_OBJECT)
  613. #define CUBIC_OBJECT           (STURM_OK_OBJECT)
  614. #define QUARTIC_OBJECT         (STURM_OK_OBJECT)
  615. #define POLY_OBJECT            (STURM_OK_OBJECT)
  616. #define BLOB_OBJECT            (STURM_OK_OBJECT)
  617. #define LIGHT_OBJECT           (COMPOUND_OBJECT+PATCH_OBJECT+LIGHT_SOURCE_OBJECT)
  618.  
  619. typedef int (*ALL_INTERSECTIONS_METHOD)PARAMS((OBJECT *, RAY *, ISTACK *));
  620. typedef int (*INSIDE_METHOD)PARAMS((VECTOR *, OBJECT *));
  621. typedef void (*NORMAL_METHOD)PARAMS((VECTOR *, OBJECT *, VECTOR *));
  622. typedef void *(*COPY_METHOD)PARAMS((OBJECT *));
  623. typedef void (*TRANSLATE_METHOD)PARAMS((OBJECT *, VECTOR *));
  624. typedef void (*ROTATE_METHOD)PARAMS((OBJECT *, VECTOR *));
  625. typedef void (*SCALE_METHOD)PARAMS((OBJECT *, VECTOR *));
  626. typedef void (*TRANSFORM_METHOD)PARAMS((OBJECT *, TRANSFORM *));
  627. typedef void (*INVERT_METHOD)PARAMS((OBJECT *));
  628. typedef void (*DESTROY_METHOD)PARAMS((OBJECT *));
  629.  
  630. struct Method_Struct
  631.   {
  632.    ALL_INTERSECTIONS_METHOD All_Intersections_Method;
  633.    INSIDE_METHOD Inside_Method;
  634.    NORMAL_METHOD Normal_Method;
  635.    COPY_METHOD Copy_Method;
  636.    TRANSLATE_METHOD Translate_Method;
  637.    ROTATE_METHOD Rotate_Method;
  638.    SCALE_METHOD Scale_Method;
  639.    TRANSFORM_METHOD Transform_Method;
  640.    INVERT_METHOD Invert_Method;
  641.    DESTROY_METHOD Destroy_Method;
  642.   };
  643.  
  644. #define All_Intersections(x,y,z) ((*((x)->Methods->All_Intersections_Method)) (x,y,z))
  645. #define Inside(x,y) ((*((y)->Methods->Inside_Method)) (x,y))
  646. #define Normal(x,y,z) ((*((y)->Methods->Normal_Method)) (x,y,z))
  647. #define Copy(x) ((*((x)->Methods->Copy_Method)) (x))
  648. #define Translate(x,y) ((*((x)->Methods->Translate_Method)) (x,y))
  649. #define Scale(x,y) ((*((x)->Methods->Scale_Method)) (x,y))
  650. #define Rotate(x,y) ((*((x)->Methods->Rotate_Method)) (x,y))
  651. #define Transform(x,y) ((*((x)->Methods->Transform_Method)) (x,y))
  652. #define Invert(x) ((*((x)->Methods->Invert_Method)) (x))
  653. #define Destroy(x) ((*((x)->Methods->Destroy_Method)) (x))
  654.  
  655. #define Destroy_Camera(x) if ((x)!=NULL) free(x)
  656.  
  657. struct Camera_Struct
  658.   {
  659.    VECTOR Location;
  660.    VECTOR Direction;
  661.    VECTOR Up;
  662.    VECTOR Right;
  663.    VECTOR Sky;
  664.   };
  665.  
  666. struct Bounding_Box_Struct {
  667.    VECTOR Lower_Left, Lengths;
  668.    };
  669.  
  670. /* These fields are common to all objects */
  671.  
  672.   #define OBJECT_FIELDS \
  673.    METHODS *Methods;\
  674.    int Type;\
  675.    OBJECT *Sibling;\
  676.    TEXTURE *Texture;\
  677.    OBJECT *Bound;\
  678.    OBJECT *Clip;\
  679.    BBOX Bounds;\
  680.    short No_Shadow_Flag;
  681.  
  682. /* These fields are common to all compound objects */
  683. #define COMPOUND_FIELDS \
  684.  OBJECT_FIELDS \
  685.  OBJECT *Children;
  686.  
  687. #define INIT_OBJECT_FIELDS(o,t,m)\
  688.  o->Type=t;o->Methods= m;o->Sibling=NULL;o->Texture=NULL;\
  689.  o->Bound=NULL;o->Clip=NULL;o->No_Shadow_Flag=FALSE;\
  690.  Make_Vector(&o->Bounds.Lower_Left, -BOUND_HUGE/2, -BOUND_HUGE/2, -BOUND_HUGE/2)\
  691.  Make_Vector(&o->Bounds.Lengths, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE)
  692.  
  693. /* This is an abstract structure that is never actually used.
  694.    All other objects are descendents of this primative type */
  695.  
  696. struct Object_Struct
  697.   {
  698.    OBJECT_FIELDS
  699.   };
  700.  
  701. struct CSG_Struct
  702.   {
  703.    COMPOUND_FIELDS
  704. #ifdef DB_CODE
  705.    /* to calculate the bounding box for CSG intersections
  706.       we need to know if the CSG is inverted or not */
  707.    unsigned short int Inverted;
  708. #endif
  709.   };
  710.  
  711. struct Light_Source_Struct
  712.   {
  713.    COMPOUND_FIELDS
  714.    COLOUR Colour;
  715.    VECTOR Center, Points_At, Axis1, Axis2;
  716.    DBL Coeff, Radius, Falloff;
  717.    LIGHT_SOURCE *Next_Light_Source;
  718.    unsigned char Light_Type, Area_Light, Jitter, Track;
  719.    int    Area_Size1, Area_Size2;
  720.    int    Adaptive_Level;
  721.    COLOUR **Light_Grid;
  722.    OBJECT *Shadow_Cached_Object;
  723. #ifdef DB_CODE
  724.    /* pointer to the light buffers for the six general directions in space */
  725.    PROJECT_TREE_NODE *Light_Buffer[6];
  726. #endif
  727.   };
  728.  
  729. /* Light source types */
  730. #define POINT_SOURCE     1
  731. #define SPOT_SOURCE      2
  732.  
  733. #define BUNCHING_FACTOR 4
  734. struct Composite_Struct
  735.   {
  736.    OBJECT_FIELDS
  737.    unsigned short int Entries;
  738.    OBJECT *Objects[BUNCHING_FACTOR];
  739.   };
  740.  
  741. #ifdef DB_CODE
  742. /* The following structure represent the bounding box hierarchy in 2d space.
  743.    Because is_leaf, Object and Project are the first elements in both
  744.    structures they can be accessed without knowing at which structure
  745.    a pointer is pointing. */
  746.  
  747. struct Project_Tree_Node_Struct
  748. {
  749.   unsigned short is_leaf;
  750.   OBJECT *Object;
  751.   PROJECT Project;
  752.   unsigned short Entries;
  753.   PROJECT_TREE_NODE **Entry;
  754. };
  755.  
  756. struct Project_Tree_Leaf_Struct
  757. {
  758.   unsigned short is_leaf;
  759.   OBJECT *Object;
  760.   PROJECT Project;
  761. };
  762.  
  763. /* The following structures have been moved from bound.c
  764.    because they are used in addon1.c */
  765.  
  766. typedef struct
  767. {
  768.   int x,y,z;
  769. }
  770. VECTORI, *pVECTORI;
  771.  
  772. typedef struct
  773. {
  774.   VECTOR slab_num;
  775.   VECTOR slab_den;
  776.   VECTORI nonzero;
  777.   VECTORI positive;
  778. }
  779. RAYINFO, *pRAYINFO;
  780.  
  781. typedef struct t_qelem
  782. {
  783.   DBL     q_key;
  784.   OBJECT *q_obj;
  785. }
  786. Qelem;
  787. #endif
  788.  
  789. struct Sphere_Struct
  790.   {
  791.    OBJECT_FIELDS
  792.    TRANSFORM *Trans;
  793.    VECTOR  Center;
  794.    DBL     Radius;
  795.    DBL     Radius_Squared;
  796.    DBL     Inverse_Radius;
  797.    VECTOR  CMOtoC, CMInitial;
  798.    DBL     CMOCSquared;
  799.    short   CMinside, CMCached, Inverted;
  800.   };
  801.  
  802. struct Quadric_Struct
  803.   {
  804.    OBJECT_FIELDS
  805.    VECTOR  Square_Terms;
  806.    VECTOR  Mixed_Terms;
  807.    VECTOR  Terms;
  808.    DBL Constant;
  809.    DBL CM_Constant;
  810.    short Constant_Cached;
  811.    short Non_Zero_Square_Term;
  812. #ifdef DB_CODE
  813.    /* In calculating the bounding box for a CSG intersection it is
  814.       necessary to know if the quadric is inverted or not! */
  815.    short Inverted;
  816. #endif
  817.   };
  818.  
  819. typedef unsigned short HF_val;
  820.  
  821. typedef struct {
  822.    HF_val min_y, max_y;
  823. } HF_BLOCK;
  824.  
  825. typedef struct {
  826.         float x, z;
  827.         VECTOR normal;
  828. } Cached_Normals;
  829.  
  830. typedef short HF_Normals[3];
  831. #define HF_CACHE_SIZE 16
  832. #define LOWER_TRI 0
  833. #define UPPER_TRI 1
  834.  
  835.  
  836.  
  837. struct Height_Field_Struct
  838.   {
  839.    OBJECT_FIELDS
  840.    TRANSFORM *Trans;
  841.    BOX *bounding_box;
  842.    DBL Block_Size;
  843.    DBL Inv_Blk_Size;
  844.    HF_BLOCK **Block;
  845.    HF_val **Map;
  846.    int Inverted;
  847.    int cache_pos;
  848.    Cached_Normals Normal_Vector[HF_CACHE_SIZE];
  849.    int Smoothed;
  850.    HF_Normals **Normals;
  851.    };
  852.  
  853. struct Box_Struct
  854.   {
  855.    OBJECT_FIELDS
  856.    TRANSFORM *Trans;
  857.    VECTOR bounds[2];
  858.    short Inverted;
  859.   };
  860.  
  861. #define MAX_ORDER 15
  862.  
  863. #define STURM_FIELDS  OBJECT_FIELDS int Sturm_Flag;
  864.  
  865. /* Number of coefficients of a three variable polynomial of order x */
  866. #define term_counts(x) (((x)+1)*((x)+2)*((x)+3)/6)
  867.  
  868. struct Poly_Struct
  869.   {
  870.    STURM_FIELDS
  871.    TRANSFORM *Trans;
  872.    short Inverted;
  873.    int Order;
  874.    DBL *Coeffs;
  875.   };
  876.  
  877. struct Disc_Struct {
  878.    OBJECT_FIELDS
  879.    TRANSFORM *Trans; /* Transformation of a Disc object */
  880.    VECTOR center;    /* Center of the disc */
  881.    VECTOR normal;    /* Direction perpendicular to the disc (plane normal) */
  882.    DBL d;            /* The constant part of the plane equation */
  883.    DBL iradius2;     /* Distance from center to inner circle of the disc */
  884.    DBL oradius2;     /* Distance from center to outer circle of the disc */
  885.    short Inverted;
  886.    };
  887.  
  888. struct Cone_Struct {
  889.    OBJECT_FIELDS
  890.    TRANSFORM *Trans;   /* Transformation of a Cone object */
  891.    short int cyl_flag; /* Is this a cone or a cylinder? */
  892.    short int closed;   /* Currently unused - for making caps on the cone */
  893.    VECTOR apex;        /* Center of the top of the cone */
  894.    VECTOR base;        /* Center of the bottom of the cone */
  895.    DBL apex_radius;    /* Radius of the cone at the top */
  896.    DBL base_radius;    /* Radius of the cone at the bottom */
  897.    DBL dist;           /* Distance to end of cone in canonical coords */
  898.    short Inverted;
  899.    };
  900.  
  901. typedef struct Bezier_Node_Struct BEZIER_NODE;
  902. typedef struct Bezier_Child_Struct BEZIER_CHILDREN;
  903. typedef struct Bezier_Vertices_Struct BEZIER_VERTICES;
  904.  
  905. struct Bezier_Child_Struct
  906.   {
  907.    BEZIER_NODE *Children[4];
  908.   };
  909.  
  910. struct Bezier_Vertices_Struct
  911.   {
  912.    float uvbnds[4];
  913.    VECTOR Vertices[4];
  914.   };
  915.  
  916. struct Bezier_Node_Struct
  917.   {
  918.    int Node_Type;      /* Is this an interior node, or a leaf */
  919.    VECTOR Center;      /* Center of sphere bounding the (sub)patch */
  920.    DBL Radius_Squared; /* Radius of bounding sphere (squared) */
  921.    int Count;          /* # of subpatches associated with this node */
  922.    void *Data_Ptr;     /* Either pointer to vertices or pointer to children */
  923.   };
  924.  
  925. #define BEZIER_INTERIOR_NODE 0
  926. #define BEZIER_LEAF_NODE 1
  927.  
  928. #define MAX_PATCH_TYPE 4
  929.  
  930. struct Bicubic_Patch_Struct
  931.   {
  932.    OBJECT_FIELDS
  933.    int Patch_Type, U_Steps, V_Steps;
  934.    VECTOR Control_Points[4][4];
  935.    VECTOR Bounding_Sphere_Center;
  936.    DBL Bounding_Sphere_Radius;
  937.    DBL Flatness_Value;
  938.    BEZIER_NODE *Node_Tree;
  939.   };
  940.    
  941. #define X_AXIS 0
  942. #define Y_AXIS 1
  943. #define Z_AXIS 2
  944.  
  945. struct Triangle_Struct
  946.   {
  947.    OBJECT_FIELDS
  948.    VECTOR  Normal_Vector;
  949.    DBL     Distance;
  950.    DBL     CMNormDotOrigin;
  951.    unsigned int  CMCached:1;
  952.    unsigned int  Dominant_Axis:2;
  953.    unsigned int  vAxis:2;  /* used only for smooth triangles */
  954.    VECTOR  P1, P2, P3;
  955.    short int Degenerate_Flag;
  956.   };
  957.  
  958. struct Smooth_Triangle_Struct
  959.   {
  960.    OBJECT_FIELDS
  961.    VECTOR  Normal_Vector;
  962.    DBL     Distance;
  963.    DBL     CMNormDotOrigin;
  964.    unsigned int  CMCached:1;
  965.    unsigned int  Dominant_Axis:2;
  966.    unsigned int  vAxis:2;         /* used only for smooth triangles */
  967.    VECTOR  P1, P2, P3;
  968.    short int Degenerate_Flag;
  969.    VECTOR  N1, N2, N3, Perp;
  970.    DBL  BaseDelta;
  971.   };
  972.  
  973. struct Plane_Struct
  974.   {
  975.    OBJECT_FIELDS
  976.    VECTOR  Normal_Vector;
  977.    DBL     Distance;
  978.    DBL     CMNormDotOrigin;
  979.    int     CMCached;
  980.   };
  981.  
  982. typedef struct {
  983.    VECTOR pos;
  984.    DBL radius2;
  985.    DBL coeffs[3];
  986.    DBL tcoeffs[5];
  987.    } Blob_Element;
  988.  
  989. typedef struct blob_list_struct *blobstackptr;
  990. struct blob_list_struct {
  991.    Blob_Element elem;
  992.    blobstackptr next;
  993.    };
  994.  
  995. typedef struct {
  996.    int type, index;
  997.    DBL bound;
  998.    } Blob_Interval;
  999.  
  1000. struct Blob_Struct
  1001.    {
  1002.    STURM_FIELDS
  1003.    TRANSFORM *Trans;
  1004.    short Inverted;
  1005.    int count;
  1006.    DBL threshold;
  1007.    Blob_Element **list;
  1008.    Blob_Interval *intervals;
  1009. };
  1010.  
  1011. #define MAX_CONTAINING_OBJECTS 10
  1012.  
  1013. struct Ray_Struct
  1014.   {
  1015.    VECTOR Initial;               /*  Xo  Yo  Zo  */
  1016.    VECTOR Direction;             /*  Xv  Yv  Zv  */
  1017.    VECTOR Initial_2;             /*  Xo^2  Yo^2  Zo^2  */
  1018.    VECTOR Direction_2;           /*  Xv^2  Yv^2  Zv^2  */
  1019.    VECTOR Initial_Direction;     /*  XoXv  YoYv  ZoZv  */
  1020.    VECTOR Mixed_Initial_Initial; /*  XoYo  XoZo  YoZo  */
  1021.    VECTOR Mixed_Dir_Dir;         /*  XvYv  XvZv  YvZv  */
  1022.    VECTOR Mixed_Init_Dir;        /*  XoYv+XvYo  XoZv+XvZo  YoZv+YvZo  */
  1023.    int Containing_Index;
  1024.    TEXTURE *Containing_Textures [MAX_CONTAINING_OBJECTS];
  1025.    DBL Containing_IORs [MAX_CONTAINING_OBJECTS];
  1026.    int Quadric_Constants_Cached;
  1027.   };
  1028.  
  1029. struct Frame_Struct
  1030.   {
  1031.    CAMERA *Camera;
  1032.    int Screen_Height, Screen_Width;
  1033.    LIGHT_SOURCE *Light_Sources;
  1034.    OBJECT *Objects;
  1035.    DBL Atmosphere_IOR, Antialias_Threshold;
  1036.    DBL Fog_Distance;
  1037.    COLOUR Fog_Colour;
  1038.    COLOUR Background_Colour;
  1039.   };
  1040.  
  1041. #define DISPLAY 1
  1042. #define VERBOSE 2
  1043. #define DISKWRITE 4
  1044. #define PROMPTEXIT 8
  1045. #define ANTIALIAS 16
  1046. #define DEBUGGING 32
  1047. #define RGBSEPARATE 64
  1048. #define EXITENABLE 128
  1049. #define CONTINUE_TRACE 256
  1050. #define VERBOSE_FILE 512
  1051. #define JITTER 1024
  1052.  
  1053. /* Definitions for ISTACK structure */
  1054.  
  1055. struct istk_entry
  1056.   {
  1057.    DBL Depth;
  1058.    VECTOR IPoint;
  1059.    VECTOR INormal;
  1060.    int NFlag;
  1061.    OBJECT *Object;
  1062.   };
  1063.  
  1064. struct istack_struct
  1065.   {
  1066.    struct istack_struct *next;
  1067.    struct istk_entry *istack;
  1068.    unsigned int top_entry;
  1069.   };
  1070.  
  1071. #define itop(i) i->istack[i->top_entry]
  1072. #define push_entry(d,v,o,i) itop(i).Depth=d; itop(i).IPoint=v; \
  1073.  itop(i).NFlag=0; itop(i).Object=o; incstack(i);
  1074. #define push_normal_entry(d,v,n,o,i) itop(i).Depth=d; itop(i).IPoint=v; \
  1075.  itop(i).INormal=n; itop(i).NFlag=1; itop(i).Object=o; incstack(i);
  1076. #define push_copy(i,e) itop(i)= *e; incstack(i);
  1077. #define pop_entry(i) (i->top_entry > 0)?&(i->istack[--i->top_entry]):NULL
  1078.  
  1079. #define MAX_STRING_INDEX 41
  1080.  
  1081. struct Reserved_Word_Struct
  1082.   {
  1083.    TOKEN Token_Number;
  1084.    char *Token_Name;
  1085.   };
  1086.  
  1087. /* Here's where you dump the information on the current token (fm. PARSE.C) */
  1088.  
  1089. struct Token_Struct
  1090.   {
  1091.    TOKEN Token_Id;
  1092.    int Token_Line_No;
  1093.    char *Token_String;
  1094.    DBL Token_Float;
  1095.    TOKEN Begin_Id;
  1096.    int Constant_Index;
  1097.    int Unget_Token, End_Of_File;
  1098.    char *Filename, *Constant_Data;
  1099.   };
  1100.  
  1101. /* Types of constants allowed in DECLARE statement (fm. PARSE.C) */
  1102.  
  1103. #define COLOUR_CONSTANT         0
  1104. #define VECTOR_CONSTANT         1
  1105. #define FLOAT_CONSTANT          2
  1106. #define PIGMENT_CONSTANT        3
  1107. #define TNORMAL_CONSTANT        4
  1108. #define FINISH_CONSTANT         5
  1109. #define TEXTURE_CONSTANT        6
  1110. #define OBJECT_CONSTANT         7
  1111. #define COLOUR_MAP_CONSTANT     8
  1112. #define TRANSFORM_CONSTANT      9
  1113. #define CAMERA_CONSTANT        10
  1114.  
  1115. /* CSG types */
  1116. #define CSG_UNION_TYPE             1
  1117. #define CSG_INTERSECTION_TYPE      2
  1118. #define CSG_DIFFERENCE_TYPE        4
  1119. #define CSG_MERGE_TYPE             8
  1120. #define CSG_SINGLE_TYPE           16
  1121.  
  1122. struct Constant_Struct
  1123.   {
  1124.    int Identifier_Number;
  1125.    CONSTANT Constant_Type;
  1126.    char *Constant_Data;
  1127.   };
  1128.  
  1129. struct Chunk_Header_Struct 
  1130.   {
  1131.    long name;
  1132.    long size;
  1133.   };
  1134.  
  1135. struct Data_File_Struct 
  1136.   {
  1137.    FILE *File;
  1138.    char *Filename;
  1139.    int Line_Number;
  1140.   };
  1141.  
  1142. struct complex_block 
  1143.   {
  1144.    DBL r, c;
  1145.   };
  1146.  
  1147. #define READ_MODE 0
  1148. #define WRITE_MODE 1
  1149. #define APPEND_MODE 2
  1150.  
  1151. struct file_handle_struct 
  1152.   {
  1153.    char *filename;
  1154.    int  mode;
  1155.    int width, height;
  1156.    int buffer_size;
  1157.    char *buffer;
  1158.    FILE *file;
  1159.    char *(*Default_File_Name_p) PARAMS((void));
  1160.    int  (*Open_File_p) PARAMS((struct file_handle_struct *handle,
  1161.            char *name, int *width, int *height, int buffer_size,
  1162.            int mode));
  1163.    void (*Write_Line_p) PARAMS((struct file_handle_struct *handle,
  1164.            COLOUR *line_data, int line_number));
  1165.    int  (*Read_Line_p) PARAMS((struct file_handle_struct *handle,
  1166.            COLOUR *line_data, int *line_number));
  1167.    void (*Read_Image_p) PARAMS((IMAGE *Image, char *filename));
  1168.    void (*Close_File_p) PARAMS((struct file_handle_struct *handle));
  1169.   };
  1170.  
  1171. typedef struct file_handle_struct FILE_HANDLE;
  1172.  
  1173. #define Default_File_Name(h) ((*((h)->Default_File_Name_p)) ())
  1174. #define Open_File(h,n,wd,ht,sz,m) ((*((h)->Open_File_p)) (h,n,wd,ht,sz,m))
  1175. #define Write_Line(h,l,n) ((*((h)->Write_Line_p)) (h, l, n))
  1176. #define Read_Line(h,l,n) ((*((h)->Read_Line_p)) (h, l, n))
  1177. #define Read_Image(h,i) ((*((h)->Read_Image_p)) (h, i))
  1178. #define Close_File(h) ((*((h)->Close_File_p)) (h))
  1179.  
  1180.  
  1181. #define Q_FULL_AMBIENT 1
  1182. #define Q_QUICKC       2
  1183. #define Q_SHADOW       4
  1184. #define Q_AREA_LIGHT   8
  1185. #define Q_REFRACT     16
  1186. #define Q_REFLECT     32
  1187. #define Q_NORMAL      64
  1188.  
  1189. #define QUALITY_0 Q_QUICKC+Q_FULL_AMBIENT
  1190. #define QUALITY_1 QUALITY_0
  1191. #define QUALITY_2 QUALITY_1-Q_FULL_AMBIENT
  1192. #define QUALITY_3 QUALITY_2
  1193. #define QUALITY_4 QUALITY_3+Q_SHADOW
  1194. #define QUALITY_5 QUALITY_4+Q_AREA_LIGHT
  1195. #define QUALITY_6 QUALITY_5-Q_QUICKC+Q_REFRACT
  1196. #define QUALITY_7 QUALITY_6
  1197. #define QUALITY_8 QUALITY_7+Q_REFLECT+Q_NORMAL
  1198. #define QUALITY_9 QUALITY_8
  1199.